const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    uId:'',
    offsetH:0,
    name:'',
    updateStates:false,
    state:false,
    popupState: true,
    matchType: "",
    gameScore: "",
    examination: {},
    winner: "1",
    ownInfo: {},
    opponentInfo: {},
    leftAnimate: {},//做动画
    rightAnimate: {}, //右动画
    animateScale: {}, //vs动画三
    userName: "澄邈、德泽、海超、海阳、海荣、海逸、海昌、瀚钰、瀚文、涵亮、涵煦、涵蓄、涵衍、浩皛、浩波、浩博、浩初、浩宕、浩歌、浩广、浩邈、浩气、浩思、浩言、鸿宝、鸿波、鸿博、鸿才、鸿畅、鸿畴、鸿达、鸿德、鸿飞、鸿风、鸿福、鸿光、鸿晖、鸿朗、鸿文、鸿轩、鸿煊、鸿骞、鸿远、鸿云、鸿哲、鸿祯、鸿志、鸿卓、嘉澍"
  },

  onShow() {

    // 左动画
    let animation = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease',
      transformOrigin: '50% 50% 0'
    })


    this.animation = animation

    animation.translateX(0).opacity(1).step()

    this.setData({
      leftAnimate: animation.export()
    })

    // 右动画
    let animation2 = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease',
      transformOrigin: '50% 50% 0',
      delay: 500
    })

    animation2.translate(0).opacity(1).step()

    this.setData({
      rightAnimate: animation2.export()
    })

    //结果
    let animation3 = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease',
      transformOrigin: '50% 50% 0',
      delay: 1000
    })

    animation3.scale(1).opacity(1).step()
    this.setData({
      animateScale: animation3.export()
    })

    setTimeout(()=>{
      this.setData({
        state:true
      })
    },2500)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 获取是否人机还是对战
    // 用户一总结果
    this.setData({
      uId: app.globalData.uId
    })
    
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          offsetH: res.windowHeight
        })
      }
    })

    this.setData({
      examination: app.globalData.examination
    })

    // 当前对战类型
    this.setData({
      matchType: app.globalData.matchType
    })

    // 得分
    this.setData({
      gameScore: app.globalData.gameScore
    })

    // 比赛结果
    this.setData({
      winner: this.data.examination.data.winner
    })

    // 发起者信息
    this.setData({
      ownInfo: app.globalData.ownInfo
    })

    this.setData({
      opponentInfo: app.globalData.opponentInfo
    })

    // 应战者信息
    // if (this.data.matchType == 'machine') {
    //   let iarr = this.data.userName.split('、')
    //   let param = {
    //     avatarUrl:"../../images/oneTwo.png",
    //     name: app.globalData.opponentInfo || iarr[Math.round(Math.random() * iarr.length-1)]
    //   }

    //   this.setData({
    //     opponentInfo: param
    //   })

    // } else {

    // }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // 关闭websocket
    wx.onSocketClose((res) => {
      console.log('WebSocket 已关闭！')
    })
  },

  onMyEvent(e) {
    this.setData({
      state: e.detail.state
    })
  },

  updateStatus(e) {
    this.setData({
      updateStates: e.detail.state
    })

    this.setData({
      name: e.detail.name
    })
  },

  switchFn(){
    this.setData({
      state: !this.state
    })
  }
})